package cn.stylefeng.guns.modular.demos.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.demos.entity.BizBlacklistLog;
import cn.stylefeng.guns.modular.demos.mapper.BizBlacklistLogMapper;
import cn.stylefeng.guns.modular.demos.model.params.BizBlacklistLogParam;
import cn.stylefeng.guns.modular.demos.model.result.BizBlacklistLogResult;
import  cn.stylefeng.guns.modular.demos.service.BizBlacklistLogService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zjj
 * @since 2020-09-09
 */
@Service
public class BizBlacklistLogServiceImpl extends ServiceImpl<BizBlacklistLogMapper, BizBlacklistLog> implements BizBlacklistLogService {

    @Override
    public void add(BizBlacklistLogParam param){
        BizBlacklistLog entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(BizBlacklistLogParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(BizBlacklistLogParam param){
        BizBlacklistLog oldEntity = getOldEntity(param);
        BizBlacklistLog newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public BizBlacklistLogResult findBySpec(BizBlacklistLogParam param){
        List<BizBlacklistLogResult> list = this.baseMapper.customList(param);
        if(list == null || list.size()<=0){
        	return null;
        }
        
        return list.get(0);
    }

	@SuppressWarnings("rawtypes")
    @Override
    public List<BizBlacklistLogResult> findListBySpec(BizBlacklistLogParam param){
        List<BizBlacklistLogResult> list = this.baseMapper.customList(param);
  
        return list;
    }
    
    @SuppressWarnings("rawtypes")
    @Override
    public List<BizBlacklistLogResult> findListBySpec2(BizBlacklistLogParam param){
        List<BizBlacklistLogResult> list = this.baseMapper.customList2(param);
  
        return list;
    }
    
    @SuppressWarnings("rawtypes")
    @Override
    public List<Map<String, Object>> findMapListBySpec(BizBlacklistLogParam param){
        List<Map<String, Object>> list = this.baseMapper.customMapList2(param);
  
        return list;
    }
    
	@SuppressWarnings("rawtypes")
    @Override
    public LayuiPageInfo findPageBySpec(BizBlacklistLogParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }
    
    /*
    *	add by zjj
    *
    */
    @SuppressWarnings("rawtypes")
	@Override
    public Page<Map<String, Object>> findPageMapListBySpec(BizBlacklistLogParam param){
        Page pageContext = getPageContext();
        return this.baseMapper.customPageMapList(pageContext, param); 
    }
    /*
    *	add by zjj
    *
    */
    @Override
    public Integer customCount(BizBlacklistLogParam param){
		return this.baseMapper.customCount(param);
	}

    private Serializable getKey(BizBlacklistLogParam param){
        return param.getId();
    }
    
	@SuppressWarnings("rawtypes")
    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private BizBlacklistLog getOldEntity(BizBlacklistLogParam param) {
        return this.getById(getKey(param));
    }

    private BizBlacklistLog getEntity(BizBlacklistLogParam param) {
        BizBlacklistLog entity = new BizBlacklistLog();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
